
import Vue from 'vue'
import Vuex from 'vuex'
import * as mutations from './mutation';
Vue.use(Vuex)

let iconUrl = require ( '../assets/success.png' );

export default new Vuex.Store({
    state: {
      employ: [],
      partnerId: '',
      // url:'114.116.106.153/api',
      // url:'106.14.199.49/backstage/api',
      // url: 'https://sharespace.cloudjoyclub.com//backstage/api',
      url: 'http://114.116.100.38/backstage/api',
      
      // baseUrl: 'https://sharespace.cloudjoyclub.com/',
      baseUrl: 'http://114.116.100.38',
      
      userId: 0,
      fn: {
        success( txt, time ) {
          let bg = document.createElement ( 'div' ),
              main = document.createElement ( 'div' ),
              icon = document.createElement ( 'img' ),
              text = document.createElement ( 'div' );

          // bg.style.background = 'rgba( 0, 0, 0, .3 )';
          bg.style.width = '100%';
          bg.style.height = '100%';
          bg.style.position = 'fixed';
          bg.style.left = 0;
          bg.style.top = 0;
          bg.style.transition = 'all ease 0.3s';
          bg.style.zIndex = 2019;

          main.style.width = '240px';
          main.style.height = '120px';
          main.style.background = 'rgba( 0, 0, 0, .8 )';
          main.style.position = 'absolute';
          main.style.left = '50%';
          main.style.top = '50%';
          main.style.marginLeft = '-90px';
          main.style.marginTop = '-40px';
          main.style.borderRadius = '10px';

          icon.style.width = '40px';
          icon.style.height = '40px';
          icon.src = iconUrl;
          icon.style.position = 'absolute';
          icon.style.left = '100px';
          icon.style.top = '20px';

          text.innerHTML = txt;
          text.style.width = '100%';
          text.style.marginTop = '70px';
          text.style.textAlign = 'center';
          text.style.color = '#fff';

          main.appendChild ( icon );
          main.appendChild ( text );
          bg.appendChild ( main );
          document.body.appendChild ( bg );

          let p = new Promise (( resolve ) => {
            bg.addEventListener ( 'webkitTransitionEnd', () => {
              document.body.removeChild ( bg );
              resolve ? resolve() : '';
            });
            setTimeout (() => {
              bg.style.opacity = 0;
            }, time ? time : 2000 );
          });
          return p;
        }
      }
    },
    mutations,
    actions: {
      //
    },
  })
